package java19_1_21;

import java.util.Scanner;

//自定义类模拟登录
public class LoginTest {
    public static final String ID = "huweilong";
    public static final String PASSWORD = "123456";

    public static void main(String[] args) {
        try {
            login();
            System.out.println("登录成功！");
        } catch (UserNameException e) {
            e.printStackTrace();
        } catch (PasswordException e) {
            e.printStackTrace();
        }
    }

    public static void login() {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入用户名：");
        String id = scanner.next();
        System.out.print("请输入密码：");
        String password = scanner.next();
        if (!id.equals(ID)) {
            throw new UserNameException("用户名错误！");
        }
        if (!password.equals(PASSWORD)) {
            throw new PasswordException("密码错误！");
        }
    }
}

//用户名验证
class UserNameException extends RuntimeException {
    public UserNameException(String msg) {
        super(msg);
    }
}

//密码验证
class PasswordException extends RuntimeException {
    public PasswordException(String msg) {
        super(msg);
    }
}
